package com.yueqian.epidemic;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.config.annotation.*;

/**
 * SpringMVC的配置类
 */
// 配置类需要@Configuration注解
@Configuration
@EnableWebMvc
// @ComponentScan: 扫描Controller的注解组件
@ComponentScan(includeFilters = @ComponentScan.Filter(type = FilterType.ANNOTATION, classes = Controller.class))
public class SpringMVCConfig extends WebMvcConfigurerAdapter {
    /**
     * 添加视图控制器
     *
     * @param registry
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        // epidemic模块下的 *.jsp
        registry.addViewController("/").setViewName("epidemic");
    }

    /**
     * 配置视图解析器
     *
     * @param registry
     */
    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        // 前缀 "/" 为web目录
        // 后缀 ".jsp"为web目录下的每一个 *.jsp文件
        // 定义了一个内部资源视图解析器(InternalResourceViewResolver)
        registry.jsp("/", ".jsp");
    }

    /**
     * 允许访问静态资源
     */
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }
}
